﻿using HealthcareSystem.API.Write.Application.Command.EquipmentCommand;
using HealthcareSystem.Domain.BasicSettings.Equipment;
using MediatR;
using Microsoft.AspNetCore.Server.HttpSys;
using WeekExam.PassPort.ErrorCode;
using WeekExam.PassPort.Infrastructure.Interface;

namespace HealthcareSystem.API.Write.Application.CommandHandel.EquipmentCommandHandler
{
    /// <summary>
    /// 设备添加请求命令
    /// </summary>
    public class EquipmentCreateCommandHandler : IRequestHandler<EquipmentCreateCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<EquipmentTable> equipRep;

        public EquipmentCreateCommandHandler(IBaseRepository<EquipmentTable> equipRep)
        {
            this.equipRep = equipRep;
        }

        public async Task<ApiResult<int>> Handle(EquipmentCreateCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();
            result.Code=ResultCode.添加成功;
            result.Message=ResultCode.添加成功.ToString();

            EquipmentTable eq=new EquipmentTable();
            eq.EquipmentBrand=request.EquipmentBrand;
            eq.EquipmentName=request.EquipmentName;
            eq.EquipmentCoding=request.EquipmentCoding;
            eq.EquipmentType=request.EquipmentType;
            eq.EquipmentSNnum=request.EquipmentSNnum;
            eq.EquipmentStatus = true;
            eq.IsDelete = false;
            eq.CreatedTime=DateTime.Now;
            await equipRep.AddAsync(eq);

            return await Task.FromResult(result);
        }
    }
}
